<?php
   include("files/php/global.php"); 
   checkLogin();
   session_start();

   $msql  = new Db;
   $msql->connect();

   $check=$_GET['check'];
   $query="SELECT data_start,data_end,nome_tab,checksum,path_file FROM delete_dati where checksum='$check'"; 
   $arr=$msql->execute_select($query);
   $ask=$_GET['ask'];
  
  
   if(false == $ask && count($arr)>0)
   {
?>
<script language="javascript">

</script>
<p>I dati sarann&ograve; eliminati dal database, precedentemente archiviati ed inviati tramite email 

</p>
<form method="post" action="EliminaDati.php?ask=true&check=<?php echo $arr[0][3]; ?>" id="login_form">
	<fieldset>
		<legend>Emlimina Dati</legend>
                <label>Elimina i dati dalla data </label>
                <input type="text" readonly name="start" value="<?php echo $arr[0][0]; ?>"/>
                <input type="text" readonly name="end" value="<?php echo $arr[0][1]; ?>"/>
                <input type="hidden" name="elimina" value="<?php echo $arr[0][1]; ?>"/>
                <input type="hidden" name="check" value="<?php echo $arr[0][3]; ?>"/>
                <input type="hidden" name="nome_tab" value="<?php echo $arr[0][2]; ?>"/>
		<input name="ubmit" type="submit" id="submit" value="Elimina" style="margin: 0px 0 0 287px;" class="button" /> <span id="msgbox" style="display:none"></span>

	</fieldset>
</form>
</body>
</html>
<?php
   }
   else if($ask && count($arr)>0)
   {
      $check=$_POST['check'];
      $nome_tab=$_POST['nome_tab'];
      $start_data=$_POST['start'];
      $end_data=$_POST['end'];
      
      //sleep(5);
      echo "----------".$arr[0][4];
      system("rm -rf ".$arr[0][4]);
      $query="delete from delete_dati where checksum='$check'"; 
      $arr=$msql->execute($query);
      $query="delete from $nome_tab where data >= '$start_data' and data <= '$end_data';"; 
      $arr=$msql->execute($query);
      header( 'Location: Home.php') ;
     
      
      echo $query;

   }
   else if(count($arr)==0)
   {
      header( 'Location: Home.php') ;
   }
   
   $msql->disconnettiDB();

?>
